﻿using System;
using System.Reflection;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using LotroTweeter.Data;
using LotroTweeter.Engine;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace LotroTweeter.UnitTests.Engine.DataEngineTests
{
    /// <summary>
    /// Summary description for KinRosterComparisons
    /// </summary>
    [TestClass]
    public class KinRosterComparisons
    {
        private XElement kinRosterBefore;
        private XElement kinRosterAfter;

        public KinRosterComparisons()
        {
            var thisAssembly = Assembly.GetExecutingAssembly();
            var beforeSource = thisAssembly.GetManifestResourceStream("LotroTweeter.UnitTests.KinRosterBefore.xml");
            var xmlReader = XmlReader.Create(beforeSource);
            kinRosterBefore = XDocument.Load(xmlReader).Root;

            var afterSource = thisAssembly.GetManifestResourceStream("LotroTweeter.UnitTests.KinRosterAfter.xml");
            xmlReader = XmlReader.Create(afterSource);
            kinRosterAfter = XDocument.Load(xmlReader).Root;
        }

        [TestMethod]
        public void ShouldDetectNewKinMembers()
        {
            var dataComparer = new DataEngine(kinRosterBefore, kinRosterAfter);
            var newMembers = dataComparer.GetNewMembers();
            Assert.AreEqual(1,newMembers.Count());
            Assert.IsTrue(newMembers.Any(m=>m.Name == "Silverleaf"));
        }

        [TestMethod]
        public void ShouldDetectLevelUps()
        {
            var dataComparer = new DataEngine(kinRosterBefore, kinRosterAfter);
            var updatedMembers = dataComparer.GetLevelUps();
            Assert.AreEqual(3, updatedMembers.Count());
        }
    }
}
